package com.it.mathdemo1;

public class MathDemo1 {
    public static void main(String[] args) {
        /*
                public static int       abs(int a)
                public static double    ceil(double a)
                public static double    floor(double a)
                public static int       round(float a)
                public static int       max(int a,int b)
                public static double    pow(double a,double b)
                public static double    random()
         */

        //abs 获取参数的绝对值
        System.out.println(Math.abs(88));//88
        System.out.println(Math.abs(-88));//88
        //bug:
        //以int类型为例，取值范围：-2147483648 ~2147483647
        //如果没有正数与负数对应，那么传递负数结果有误
        //System.out.println(Math.abs(-2147483648));
        //System.out.println(Math.absExact(-2147483648));//会给你提示错误

        //进一法：往数轴的正方向进一
        System.out.println(Math.ceil(12.34));//13.0
        System.out.println(Math.ceil(12.54));//13.0
        System.out.println(Math.ceil(-12.34));//-12.0
        System.out.println(Math.ceil(-12.54));//-12.0

        //去尾法
        System.out.println("---------------------");
        System.out.println(Math.floor(12.34));//12.0
        System.out.println(Math.floor(12.54));//12.0
        System.out.println(Math.floor(-12.34));//-13.0
        System.out.println(Math.floor(-12.54));//-13.0

        //round四舍五入
        System.out.println("---------------------");
        System.out.println(Math.round(12.34));//12
        System.out.println(Math.round(12.54));//13

        //比大小
        System.out.println("---------------------");
        System.out.println(Math.max(12,13));//13
        System.out.println(Math.min(12,13));//12
    }
}
